import ServiceChat from './views/ServiceChat.vue';

const loadCss = async (url) => {
	return new Promise((resolve, reject) => {
		const link = document.createElement('link');
		link.rel = 'stylesheet';
		link.href = url;
		link.onload = () => resolve();
		link.onerror = reject;
		document.head.appendChild(link);
	});
};

const ServiceChatPlugin = {
	install: async (app) => {
		app.component('ServiceChat', ServiceChat);
		// 动态加载CSS
		try {
			await loadCss(
				new URL('../dist/service-chat.css', import.meta.url).toString()
			);
		} catch (e) {
			console.error('Failed to load CSS', e);
		}
	},
};

export default ServiceChatPlugin;
